// components/heart-item/index.js
import { HeartModel} from '../../model/heart'
var heart = new HeartModel()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model:Object
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    ownAction(e){
      var data = e.currentTarget.dataset
      console.log(data)
    },
    detailAction(e){
      var data = e.currentTarget.dataset
      console.log(data)
      wx.navigateTo({
        url: '/pages/heart/detail/detail?id=' + data.id,
      })
    },
    followAction(e){
      var data = e.currentTarget.dataset
      heart.collection(data.id,data.isfollow,12).then(
        res=>{
          if (res.code === 0) {
            this.triggerEvent("upData")
          }
        }
      )
      console.log(data.isfollow)
    },

    tailAction(e){
      var data = e.currentTarget.dataset
      switch (data.index) {
        case 0:
          console.log("分享")
          break;
        case 1:
          console.log("评论")
          wx.showToast({
            title: '该功能暂未开发',
            icon: 'none'
          })
          break;
        case 2:
          heart.collection(data.id,data.selected).then(
            res=>{
              if (res.code === 0) {
                this.triggerEvent("upData")
              }
            }
          )
          break;
        case 3:
          heart.praise(data.id,data.selected).then(
            res=>{
              if (res.code === 0) {
                this.triggerEvent("upData")
              }
            }
          )
          break;
      
        default:
          break;
      }
      console.log(data)
    }
  }
})
